import { createStore } from 'vuex'

export default createStore({
  state: {
    token: localStorage.getItem('token') ? localStorage.getItem('token') : '',
    userinfo: localStorage.getItem('userinfo') ? JSON.parse(localStorage.getItem('userinfo')) : '',
    isLogin: false
  },
  getters: {
    getUserinfo (state) {
      return state.userinfo
    }
  },
  mutations: {
    changeToken (state, token) {
      state.token = token
      localStorage.setItem('token', token)
    },
    changeUserinfo (state, userinfo) {
      state.userinfo = userinfo
      localStorage.setItem('userinfo', JSON.stringify(userinfo))
    },
    removeUserinfo (state, payload) {
      state.userinfo = null
      state.isLogin = payload
    }
  },
  actions: {
  },
  modules: {
  }
})
